﻿using System;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;
using Limestone;
using Limestone.Fields;
using Limestone.MVC;
using Limestone.Storage.XML;

namespace SampleSite.Configuration
{


    public class LimestoneModule : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<PageProvider>().As<IPageProvider>();
            builder.RegisterType<TemplateProvider>().As<ITemplateProvider>();
            builder.RegisterType<PageStubCache>().As<IPageStubCache>();
            builder.RegisterType<Trashcan>().As<ITrashcan>();

            builder.Register(c => new GetCurrentUserFromHttpContext(HttpContext.Current)).As<IGetCurrentUserId>();

            builder.RegisterType<XmlStorageConfig>().As<IXmlStorageConfig>();
            builder.RegisterType<XmlStorage>().As<IStorage>();
            builder.Register(c => new XmlStorageConfig(HttpContext.Current)).As<IXmlStorageConfig>();

        /*    builder.Register(c =>
                new XmlStorage(HttpContext.Current.Server.MapPath("/Pages/"),
                               HttpContext.Current.Server.MapPath("/Templates/"),
                               HttpContext.Current.Server.MapPath("/Trashcan/"),
                               new GetCurrentUserFromHttpContext(HttpContext.Current))).As<IStorage>();
            */
            builder.RegisterModelBinderProvider();
            builder.RegisterModelBinders(new Assembly[] { typeof(AbstractFieldBinder).Assembly, Assembly.GetExecutingAssembly() });
        }
    }
}